﻿using BlockGame.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BlockGame.Game
{
    public class GameCore
    {
        #region # VARIABLEN #

        private Boolean IsPlaying = true;
        private ConsoleKeyInfo KeyData = new ConsoleKeyInfo();
        
        #endregion

        #region # KONSTRUKTOREN #

        public GameCore()
        {
        }

        #endregion

        #region # ÖFFENTLICHE FUNKTIONEN #

        public void Start()
        {
            InitGameField();

            while (IsPlaying)
            {
                KeyData = new ConsoleKeyInfo();

                DrawGameField();

                KeyData = Console.ReadKey();

                switch (KeyData.Key)
                {
                    case ConsoleKey.Escape:
                        {
                            // Pausenmenü anzeigen
                        } break;
                    case ConsoleKey.DownArrow:
                        {
                            // Nach unten bewegen
                        } break;
                    case ConsoleKey.UpArrow:
                        {
                            // Nach oben bewegen
                        } break;
                    case ConsoleKey.LeftArrow:
                        {
                            // Nach links bewegen
                        } break;
                    case ConsoleKey.RightArrow:
                        {
                            // Nach rechts bewegen
                        } break;
                }
            }
        }

        #endregion

        #region # PRIVATE FUNKTIONEN #

        private void InitGameField()
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.DarkGray;
            Console.Clear();

            // Rahmen zeichnen
            Int32 WHeight = Console.WindowHeight;
            Int32 WWidth = Console.WindowWidth;
            Int32 i = 0;

            // Erste und Letzte Zeile
            Console.SetCursorPosition(0, 0);
            for (i = 0; i <= (WWidth - 2); i++)
            {
                Console.Write(CharElements.Element1);
            }
            Console.SetCursorPosition(0, (WHeight - 2));
            for (i = 0; i <= (WWidth - 2); i++)
            {
                Console.Write(CharElements.Element1);
            }

            // Linker und Rechter Rand
            for (i = 0; i <= (WHeight - 2); i++)
            {
                Console.SetCursorPosition(0, i);
                Console.Write(CharElements.Element2);
            }
            for (i = 0; i <= (WHeight - 2); i++)
            {
                Console.SetCursorPosition((WWidth - 2), i);
                Console.Write(CharElements.Element2);
            }

            // Vier Ecken
            Console.SetCursorPosition(0, 0);
            Console.Write(CharElements.Element3);

            Console.SetCursorPosition((WWidth - 2), 0);
            Console.Write(CharElements.Element4);

            Console.SetCursorPosition(0, (WHeight - 2));
            Console.Write(CharElements.Element5);

            Console.SetCursorPosition((WWidth - 2), (WHeight - 2));
            Console.Write(CharElements.Element6);
        }

        private void DrawGameField()
        {
        }

        #endregion
    }
}
